package homework.work9;

import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

public class ClientHandler implements Runnable {
    private Socket socket;

    public ClientHandler(Socket socket) {
        this.socket = socket;
    }

    //    @Override
//    public void run() {
//        try {
//            InputStream in = socket.getInputStream();
//            int i;
//            while ((i=in.read()) != -1) {
//                System.out.println((char) i);
//            }
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
    @Override
    public void run() {
        try {
            InputStream in = socket.getInputStream();
            StringBuilder builder = new StringBuilder();
            char pre = 'a',cur;
            while (true) {
                 cur = (char) in.read();
                 if(cur == 10 && pre == 13) {
                     break;
                 }
                 builder = builder.append(cur);
                 pre=cur;
            }
            String s = builder.toString().trim();
            System.out.println(s);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
